```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java调用C语言SDK方法详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .title {
            font-family: 'Noto Serif SC', serif;
        }
        .method-card {
            transition: all 0.3s ease;
        }
        .method-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.1);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 6px;
            font-family: 'Courier New', Courier, monospace;
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
        }
        .comparison-table th, .comparison-table td {
            padding: 12px 15px;
        }
        .comparison-table tr:nth-child(even) {
            background-color: #f8f9fa;
        }
        .comparison-table tr:hover {
            background-color: #f1f3f5;
        }
        .footer {
            background-color: #1a1a1a;
        }
        .footer a:hover {
            color: #6e8efb;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="title text-4xl md:text-5xl font-bold mb-6">Java调用C语言SDK方法详解</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">探索Java与C语言互操作的三种高效方式</p>
            <div class="flex justify-center space-x-4">
                <div class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                    <i class="fas fa-code mr-2"></i>
                    <span>JNI</span>
                </div>
                <div class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                    <i class="fas fa-exchange-alt mr-2"></i>
                    <span>JNA</span>
                </div>
                <div class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                    <i class="fas fa-terminal mr-2"></i>
                    <span>Process</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="prose max-w-none">
                <h2 class="text-3xl font-bold mb-6">Java与C语言互操作概述</h2>
                <p class="text-lg text-gray-700 leading-relaxed">
                    在Java开发中，有时需要调用C语言编写的库或SDK来实现高性能计算或访问底层系统功能。本文将详细介绍Java调用C语言的三种主流方法：JNI (Java Native Interface)、JNA (Java Native Access) 和 Process API，帮助您根据项目需求选择最佳方案。
                </p>
            </div>
        </section>

        <!-- JNI Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden method-card">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-blue-100 text-blue-800 p-3 rounded-full mr-4">
                            <i class="fas fa-microchip text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold">1. JNI (Java Native Interface)</h2>
                    </div>
                    
                    <div class="prose max-w-none">
                        <p class="text-gray-700 mb-6">
                            JNI是Java官方提供的与本地代码(C/C++)交互的方式，适用于高性能需求或需要调用底层系统API的场景。
                        </p>
                        
                        <h3 class="text-xl font-semibold mt-8 mb-4">实现步骤</h3>
                        <ol class="space-y-6">
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">1</span>
                                <div>
                                    <h4 class="font-medium">编写Java代码声明本地方法</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-java">public class NativeLib {
    // 声明本地方法
    public native int add(int a, int b);
    
    // 加载动态库
    static {
        System.loadLibrary("mylib"); // 加载 mylib.dll 或 mylib.so
    }

    public static void main(String[] args) {
        NativeLib lib = new NativeLib();
        System.out.println("Result: " + lib.add(3, 5));
    }
}</code></pre>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">2</span>
                                <div>
                                    <h4 class="font-medium">编译Java代码并生成C头文件</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-shell">javac NativeLib.java
javah -jni NativeLib  # 生成NativeLib.h</code></pre>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">3</span>
                                <div>
                                    <h4 class="font-medium">实现C代码</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-c">#include "NativeLib.h"
#include &lt;stdio.h&gt;

JNIEXPORT jint JNICALL Java_NativeLib_add(JNIEnv *env, jobject obj, jint a, jint b) {
    return a + b;
}</code></pre>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">4</span>
                                <div>
                                    <h4 class="font-medium">编译C代码生成动态库</h4>
                                    <div class="flex flex-col md:flex-row gap-4 mt-2">
                                        <div class="flex-1">
                                            <h5 class="font-medium text-sm mb-2">Windows (MinGW)</h5>
                                            <div class="code-block p-3">
<pre><code class="language-shell">gcc -shared -o mylib.dll -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" NativeLib.c</code></pre>
                                            </div>
                                        </div>
                                        <div class="flex-1">
                                            <h5 class="font-medium text-sm mb-2">Linux/macOS</h5>
                                            <div class="code-block p-3">
<pre><code class="language-shell">gcc -shared -o libmylib.so -fPIC -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" NativeLib.c</code></pre>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">5</span>
                                <div>
                                    <h4 class="font-medium">运行Java程序</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-shell">java -Djava.library.path=. NativeLib</code></pre>
                                    </div>
                                </div>
                            </li>
                        </ol>
                    </div>
                </div>
            </div>
        </section>

        <!-- JNA Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden method-card">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-purple-100 text-purple-800 p-3 rounded-full mr-4">
                            <i class="fas fa-exchange-alt text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold">2. JNA (Java Native Access)</h2>
                    </div>
                    
                    <div class="prose max-w-none">
                        <p class="text-gray-700 mb-6">
                            JNA通过动态代理方式调用本地C语言库，比JNI更易用，适合快速集成现有C库。
                        </p>
                        
                        <h3 class="text-xl font-semibold mt-8 mb-4">实现步骤</h3>
                        <ol class="space-y-6">
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">1</span>
                                <div>
                                    <h4 class="font-medium">引入JNA依赖</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-xml">&lt;dependency&gt;
    &lt;groupId&gt;net.java.dev.jna&lt;/groupId&gt;
    &lt;artifactId&gt;jna&lt;/artifactId&gt;
    &lt;version&gt;5.12.1&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">2</span>
                                <div>
                                    <h4 class="font-medium">编写Java代码</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-java">import com.sun.jna.Library;
import com.sun.jna.Native;

public class JNADemo {
    // 定义接口映射到C语言动态库
    public interface CLibrary extends Library {
        CLibrary INSTANCE = Native.load("mylib", CLibrary.class);

        int add(int a, int b);
    }

    public static void main(String[] args) {
        int result = CLibrary.INSTANCE.add(3, 5);
        System.out.println("Result: " + result);
    }
}</code></pre>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">3</span>
                                <div>
                                    <h4 class="font-medium">编写并编译C代码</h4>
                                    <div class="flex flex-col md:flex-row gap-4 mt-2">
                                        <div class="flex-1">
                                            <div class="code-block p-4">
<pre><code class="language-c">#include &lt;stdio.h&gt;

__declspec(dllexport) int add(int a, int b) {
    return a + b;
}</code></pre>
                                            </div>
                                        </div>
                                        <div class="flex-1">
                                            <div class="code-block p-4">
<pre><code class="language-shell"># Windows
gcc -shared -o mylib.dll mylib.c

# Linux/macOS
gcc -shared -o libmylib.so -fPIC mylib.c</code></pre>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-gray-200 text-gray-800 font-bold rounded-full h-8 w-8 flex items-center justify-center mr-3">4</span>
                                <div>
                                    <h4 class="font-medium">运行Java程序</h4>
                                    <div class="code-block mt-2 p-4 overflow-x-auto">
<pre><code class="language-shell">java -Djava.library.path=. JNADemo</code></pre>
                                    </div>
                                </div>
                            </li>
                        </ol>
                    </div>
                </div>
            </div>
        </section>

        <!-- Process Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden method-card">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-6">
                        <div class="bg-green-100 text-green-800 p-3 rounded-full mr-4">
                            <i class="fas fa-terminal text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold">3. 使用Process运行C语言可执行程序</h2>
                    </div>
                    
                    <div class="prose max-w-none">
                        <p class="text-gray-700 mb-6">
                            如果C语言部分是一个独立程序，可以通过Java的Process API启动并获取输出。
                        </p>
                        
                        <h3 class="text-xl font-semibold mt-8 mb-4">实现步骤</h3>
                        <div class="grid md:grid-cols-2 gap-6">
                            <div>
                                <h4 class="font-medium mb-2">Java代码</h4>
                                <div class="code-block p-4 overflow-x-auto">
<pre><code class="language-java">import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ProcessDemo {
    public static void main(String[] args) throws Exception {
        Process process = Runtime.getRuntime()
            .exec("./mylib 3 5");
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(
                process.getInputStream()));
        String output = reader.readLine();
        System.out.println("Result: " + output);
        process.waitFor();
    }
}</code></pre>
                                </div>
                            </div>
                            <div>
                                <h4 class="font-medium mb-2">C代码</h4>
                                <div class="code-block p-4 overflow-x-auto">
<pre><code class="language-c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Usage: mylib &lt;num1&gt; &lt;num2&gt;\n");
        return 1;
    }
    int a = atoi(argv[1]);
    int b = atoi(argv[2]);
    printf("%d\n", a + b);
    return 0;
}</code></pre>
                                </div>
                                <div class="code-block mt-4 p-3">
<pre><code class="language-shell">gcc -o mylib mylib.c  # 编译
java ProcessDemo      # 运行</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6 md:p-8">
                    <h2 class="text-2xl font-bold mb-6">方法对比</h2>
                    <div class="overflow-x-auto">
                        <table class="w-full comparison-table">
                            <thead>
                                <tr class="bg-gray-100">
                                    <th class="text-left py-3 px-4 font-semibold">方法</th>
                                    <th class="text-left py-3 px-4 font-semibold">适用场景</th>
                                    <th class="text-left py-3 px-4 font-semibold">优点</th>
                                    <th class="text-left py-3 px-4 font-semibold">缺点</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="py-3 px-4 font-medium">JNI</td>
                                    <td class="py-3 px-4">高性能、底层API调用</td>
                                    <td class="py-3 px-4">速度快，直接操作内存</td>
                                    <td class="py-3 px-4">需要编写C代码，复杂</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4 font-medium">JNA</td>
                                    <td class="py-3 px-4">调用现有C库，开发简单</td>
                                    <td class="py-3 px-4">代码少，易用</td>
                                    <td class="py-3 px-4">性能略低于JNI</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4 font-medium">Process</td>
                                    <td class="py-3 px-4">直接调用C语言可执行文件</td>
                                    <td class="py-3 px-4">适用于独立的C进程</td>
                                    <td class="py-3 px-4">需要额外的进程管理</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>

        <!-- Conclusion -->
        <section class="bg-blue-50 rounded-xl p-6 md:p-8 mb-16">
            <div class="flex items-start">
                <div class="bg-blue-100 text-blue-800 p-3 rounded-full mr-4">
                    <i class="fas fa-lightbulb text-xl"></i>
                </div>
                <div>
                    <h2 class="text-2xl font-bold mb-4">选择建议</h2>
                    <div class="prose max-w-none">
                        <ul class="space-y-2">
                            <li>
                                <strong>需要高性能和深度集成：</strong> 建议使用 <span class="font-mono bg-blue-100 px-2 py-1 rounded">JNI</span>
                            </li>
                            <li>
                                <strong>简单调用C语言库：</strong> 推荐使用 <span class="font-mono bg-purple-100 px-2 py-1 rounded">JNA</span>
                            </li>
                            <li>
                                <strong>C语言部分是独立程序：</strong> 使用 <span class="font-mono bg-green-100 px-2 py-1 rounded">Process</span> 方式最简单
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 md:p-8">
                <h2 class="text-2xl font-bold mb-6">方法选择流程图</h2>
                <div class="mermaid">
                    graph TD
                        A[需要调用C语言功能] --> B{性能要求高?}
                        B -->|是| C[JNI]
                        B -->|否| D{是独立可执行程序?}
                        D -->|是| E[Process]
                        D -->|否| F[JNA]
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="footer text-white py-8">
        <div class="container mx-auto max-w-5xl px-4 text-center">
            <div class="flex flex-col md:flex-row justify-center items-center space-y-2 md:space-y-0 md:space-x-6">
                <span>技术小馆</span>
                <span class="hidden md:block">|</span>
                <a href="http://www.yuque.com/jtostring" class="hover:text-blue-300 transition-colors">http://www.yuque.com/jtostring</a>
            </div>
            <div class="mt-4 text-gray-400 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```